1. Field of the Invention
The present invention pertains to compilers and software programming. More particularly, this invention relates to generating multiple processor-specific code segments in a single executable.
2. Background of the Invention
Modem computer systems can have any of a wide range and variety of configurations. One important component of a computer system is the processor, also referred to as the central processing unit (CPU). The processor executes instructions from a software program, a process referred to as xe2x80x9crunningxe2x80x9d the program. Although typically all processors perform this basic task, a wide variety of different processors are available from a number of different manufacturers. These different processors, especially those from different manufacturers, have different internal designs, also referred to as the processor xe2x80x9carchitecturexe2x80x9d, and thus operate in different ways. Although the results from running a program on two different processors are typically the same, the way in which the processor obtains the result, as well as its speed, typically differ.
Many conventional processors, such as the Pentium(copyright) Pro processor and Pentium(copyright) processor with MMX(trademark) technology (both available from Intel Corporation of Santa Clara, Calif.) are based on an architecture referred to as xe2x80x9cx86xe2x80x9d. Software programs can be written which are executable by any x86-compatible processor. However, various changes can also be made to a software program in order to allow it to be executed faster by a particular processor type. By way of example, a Pentium(copyright) processor with MMX(trademark) technology is capable of executing additional instructions, i.e., those associated with the MMX(trademark) technology, which a Pentium(copyright) Pro processor is not capable of executing. Given the advantages of using such instructions, it would be beneficial to provide a way for a programmer to include code customized to both the Pentium(copyright) processor with MMX(trademark) technology and the Pentium(copyright) Pro processor in the same program.
However, a software programmer also typically wants his or her code to be executable by as many processors as possible, thereby allowing a greater share of the market to purchase his or her product. This desire, then, is balanced against the programmer""s desire to write code that works efficiently and makes the best use of the processor which is executing it. One way to do so is to write a separate program for each possible processor which might execute the program. However, such a solution is problemsome in that it is time-intensive and costly, often resulting in a large amount of unnecessary duplication.
Another solution is to write a single program which includes different routines or functions designed to take advantage of the various capabilities of the processors which may run the program. However, one problem with this solution is that most programming languages do not allow multiple functions to have the same function name. Thus, the programmer must give the different functions for the different processors different names and correctly manage these different names throughout the rest of the program. This can be particularly difficult due to the requirement that all portions of the code must correctly identify the different functions by their different names. Thus, a need exists for an improved way to customize programs for specific processors.
In one embodiment, a method is disclosed which includes a compiler analyzing a source code segment. The compiler determines whether generating a customized version of object code for the source code segment to execute on one of several types of processors would provide a performance advantage over generating a non-customized version of object code. If so, the compiler generates the customized version of object code; otherwise, the compiler generates the non-customized version of object code.
In another embodiment, a processor executes a compiler program that includes the operations of the compiler program analyzing a source code segment, and the compiler program determining whether generating a customized version of object code for the source code segment to execute on one of several types of processors would provide a performance advantage over generating a non-customized version of object code. If so, the compiler program generates the customized version of object code; otherwise, the compiler program generates the non-customized version of object code.
In yet another embodiment, a computer-readable medium contains computer instructions for instructing a processor, the instructions including analyzing a source code segment, and determining whether generating a customized version of object code for the source code segment to execute on one of several types of processors would provide a performance advantage over generating a non-customized version of object code. If so, the customized version of object code is generated; otherwise, the non-customized version of object code is generated.
Other embodiments are disclosed and claimed.